<template>
  <el-dialog
    :title="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"
    :close-on-click-modal="false"
    :visible.sync="visible"
    class="JADP-dialog JADP-dialog_center"
    lock-scroll
    width="600px"
  >
    <el-row :gutter="15" class="">
      <el-form
        ref="elForm"
        :model="dataForm"
        :rules="rules"
        size="small"
        label-width="100px"
        label-position="right"
        :disabled="!!isDetail"
      >
        <el-col :span="24">
          <el-form-item label="评价分类" prop="categore">
            <el-select
              v-model="dataForm.categore"
              placeholder="请选择"
              clearable
              :style="{ width: '100%' }"
              :multiple="false"
            >
              <el-option
                v-for="(item, index) in categoreOptions"
                :key="index"
                :label="item.fullName"
                :value="item.id"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item label="评价项目" prop="name">
            <el-input
              type="textarea"
              v-model="dataForm.name"
              placeholder="请输入不超过30个字符"
              :rows="3"
              maxlength="30"
              show-word-limit
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import { previewDataInterface } from "@/api/systemData/dataInterface";
import ExportBox from "./ExportBox";
export default {
  components: { ExportBox },
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      activeName: "",
      dataForm: {
        categore: "",
        name: undefined,
        creatoruserid: "",
        creatortime: "",
        lastmodifyuserid: "",
        lastmodifytime: "",
        organizeId:""
      },
      rules: {
        categore: [
          {
            required: true,
            message: "请选择",
            trigger: "change"
          }
        ],
        name: [
          {
            required: true,
            message: "请输入",
            trigger: "blur"
          }
        ]
      },
      categoreOptions: []
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getcategoreOptions();
  },
  mounted() {},
  methods: {
    getcategoreOptions() {
      getDictionaryDataSelector("0c07d00707d9469cb91e8bc16659a21e").then(
        res => {
          this.categoreOptions = res.data.list;
        }
      );
    },
    init(id, isDetail) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.isDetail = isDetail || false;
      this.$nextTick(() => {
        this.$refs["elForm"].resetFields();
        if (this.dataForm.id) {
          this.loading = true;
          request({
            url: "/api/xy_pj_base/Xy_pj_base/" + this.dataForm.id,
            method: "get"
          }).then(res => {
            this.dataForm = res.data;
            this.loading = false;
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["elForm"].validate(valid => {
        if (valid) {
          this.dataForm.organizeId = this.$store.getters.organizeId;

          if (!this.dataForm.id) {
            request({
              url: `/api/xy_pj_base/Xy_pj_base`,
              method: "post",
              data: this.dataForm
            }).then(res => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  (this.visible = false), this.$emit("refresh", true);
                }
              });
            });
          } else {
            request({
              url: "/api/xy_pj_base/Xy_pj_base/" + this.dataForm.id,
              method: "PUT",
              data: this.dataForm
            }).then(res => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refresh", true);
                }
              });
            });
          }
        }
      });
    }
  }
};
</script>
